
import logging
import rasterio
import rasterio.features


logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)


def main(args):
    with rasterio.open(args.src) as dataset:
        mask = dataset.dataset_mask()

        # Extract feature shapes and values from the array.
        for geom, val in rasterio.features.shapes(mask, transform=dataset.transform):
            # 切换参考系 EPSG:32631 -> EPSG:4326 (CRS84)
            geom = rasterio.warp.transform_geom(dataset.crs, 'EPSG:4326', geom, precision=6)
            print(geom)


if __name__ == '__main__':
    import argparse
    parser = argparse.ArgumentParser()
    parser.add_argument('src')
    args = parser.parse_args()
    main(args)
